package udpPrac;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Scanner;

public class Send {
    public static void main(String[] args) throws IOException {
        DatagramSocket ds = new DatagramSocket();

        Scanner sc=new Scanner(System.in);

        //要发送的数据
        while (true) {
            System.out.println("请输入您要说的话：");
            String str = sc.nextLine();
            if("886".equals(str))//发送数据结束
            {break;
            }

            //准备要发送的数据并进行打包
            byte[] bytes = str.getBytes();
            InetAddress address = InetAddress.getByName("127.0.0.1");
            int port=10086;
            DatagramPacket dp = new DatagramPacket(bytes, bytes.length, address,port);
            ds.send(dp);
        }
        ds.close();

    }
}
